#include <S3C2440addr.h>
#include <UartDrv.h>
#include <KeyDrv.h>
#include <eventQueue.h>
#include <timer.h>

void int_service() {
    unsigned char w = rINTOFFSET;
    unsigned char subw = rSUBSRCPND;
    Queue_Element e;

    switch (w) {
    case 1://EINT1:key1
        e.cmd = CMD_KEY1_DOWN;
        push_event(&g_Main_Queue, &e);
        break;
    case 4://EINT4-7:key2
        e.cmd = CMD_KEY2_DOWN;
        push_event(&g_Main_Queue, &e);
        rEINTPEND = (1 << 4);// write EINTPEND.bit4 by 1 to clear interupt.
        break;
    case 2://EINT2:key3
        e.cmd = CMD_KEY3_DOWN;
        push_event(&g_Main_Queue, &e);
        break;
    case 0://EINT0:key4
        e.cmd = CMD_KEY4_DOWN;
        push_event(&g_Main_Queue, &e);
        break;
    case 12:
        on_timer_loop();
        break;
    case 28://0x1C
        if (subw & 0x1) { //INT_RXD0
            uart_on_recv_intr(rURXH0);
            rSUBSRCPND = (1 << 0);
        } else if (subw & 0x2) { //INT_TXD0
            uart_on_send_done_intr();
            rSUBSRCPND = (1 << 1);
        }
        break;
    default:
        ;
    }

    rSRCPND = (1 << w);
    rINTPND = (1 << w);
}



